# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=fftw

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.3.4
pkgrel=2
pkgdesc="A library for computing the discrete Fourier transform (DFT) (mingw-w64)"
arch=('any')
url="http://www.fftw.org"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("$url/fftw-$pkgver.tar.gz")
md5sums=('2edab8c06b24feeb3b82bbb3ebf3e7b3')

build() {
  cd "${srcdir}/fftw-${pkgver}"
  mkdir -p build-${MINGW_CHOST}-d && pushd build-${MINGW_CHOST}-d
  ../configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-sse2 \
    --enable-avx \
    --enable-static \
    --enable-shared \
    --enable-threads=win32 \
    --with-our-malloc \
    --with-g77-wrappers \
    --with-windows-f77-mangling
  make
  popd
  
  mkdir -p build-${MINGW_CHOST}-ld && pushd build-${MINGW_CHOST}-ld
  ../configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-long-double \
    --enable-static \
    --enable-shared \
    --enable-threads=win32 \
    --with-our-malloc \
    --with-g77-wrappers \
    --with-windows-f77-mangling
  make
  popd

  mkdir -p build-${MINGW_CHOST}-f && pushd build-${MINGW_CHOST}-f
  ../configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-float \
    --enable-sse2 \
    --enable-avx \
    --enable-static \
    --enable-shared \
    --enable-threads=win32 \
    --with-our-malloc \
    --with-g77-wrappers \
    --with-windows-f77-mangling
  make
  popd
}

package() {
  cd "${srcdir}/fftw-${pkgver}/build-${MINGW_CHOST}-d"
  make DESTDIR="$pkgdir" install
  cd "${srcdir}/fftw-${pkgver}/build-${MINGW_CHOST}-ld"
  make DESTDIR="$pkgdir" install
  cd "${srcdir}/fftw-${pkgver}/build-${MINGW_CHOST}-f"
  make DESTDIR="$pkgdir" install

  #rm "${pkgdir}"${MINGW_PREFIX}/bin/*.exe
  #rm "${pkgdir}${MINGW_PREFIX}/bin/fftw-wisdom-to-conf"
  #rm -r "${pkgdir}${MINGW_PREFIX}/share"
}
